//
//  TalkCollectionview.m
//  Bettle
//
//  Created by panhongliu on 2017/1/15.
//  Copyright © 2017年 panhongliu. All rights reserved.
//

#import "TalkCollectionview.h"
#import "TalkCollectionViewCell.h"

@implementation TalkCollectionview


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self=[super initWithFrame:frame]) {
        self.backgroundColor=[UIColor redColor];
        flowLayout= [[UICollectionViewFlowLayout alloc]init];
        
        flowLayout.minimumLineSpacing = 0;
        
        flowLayout.scrollDirection =UICollectionViewScrollDirectionHorizontal;

        self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, self.height) collectionViewLayout:flowLayout];
        
        
        [self.collectionView registerClass:[TalkCollectionViewCell class] forCellWithReuseIdentifier:@"TalkCollectionViewCell"];
        
     
        
        self.collectionView.delegate = self;
        self.collectionView.dataSource = self;
        [self addSubview:self.collectionView];
        
        
    }
    return self;
    
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    NSLog(@"ssd");
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section

{
    
    return 5;
    
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 10;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    WeakSelf(weakSelf, self);
    
        TalkCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TalkCollectionViewCell" forIndexPath:indexPath];
    cell.backgroundColor=[UIColor redColor];
    
        
        return cell;
    
}

//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(self.width,self.height);
    
    
}
//定义每个UICollectionView 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    
    return UIEdgeInsetsMake(0, 0,0, 0);
    
    
    
}

@end
